import { delay } from 'redux-saga'
import { all, put, takeEvery } from 'redux-saga/effects'

function* increment() {
    yield put({ type: 'increment' }) // 相当于：dispatch({ type: 'increment' })
}
function* incrementAsync() {
    // 延迟1s
    yield delay(1000)
    // 1s后，dispatch({ type: 'increment' })
    yield put({ type: 'increment' })
}
function* watchIncrement() {
    yield takeEvery('increment_saga', increment) // 监听类型为increment_saga的action，监听到启动increment

    // 监听类型为incrementAsync_saga的action，监听到启动incrementAsync
    yield takeEvery('incrementAsync_saga', incrementAsync)
}
function* slaughterSaga() {
    yield all([watchIncrement()]) // 启动watchIncrement
}

export default slaughterSaga;
